package com.example.financecollegeorderdish.ui

import com.drake.channel.sendEvent
import com.example.financecollegeorderdish.databinding.ActivityMineralInputBinding
import com.example.financecollegeorderdish.db.bean.MineralBean
import com.quyunshuo.androidbaseframemvvm.base.mvvm.vm.EmptyViewModel
import com.wuhao.lib_base.mvvm.v.BaseActivity
import com.wuhao.lib_common.utils.NotNullHelper
import io.reactivex.rxjava3.core.Observable
import java.util.concurrent.TimeUnit

class MineralInputActivity : BaseActivity<ActivityMineralInputBinding, EmptyViewModel>() {
    override val mViewModel: EmptyViewModel
        get() = EmptyViewModel()

    override fun createVB(): ActivityMineralInputBinding =
        ActivityMineralInputBinding.inflate(layoutInflater)

    override fun initObserve() {
    }

    override fun initRequestData() {
    }

    override fun ActivityMineralInputBinding.initView() {
        mBinding.btnOk.setOnClickListener {
            getMineralData()
            newRx.add(Observable.timer(500, TimeUnit.MILLISECONDS)
                .subscribe {
                    finish()
                })
        }
        mBinding.btnCancel.setOnClickListener { finish() }
    }

    private fun getMineralData() {
        sendEvent(
            MineralBean(
                getContent(mBinding.iron.text.toString()),//铁
                getContent(mBinding.manganese.text.toString()),//锰
                getContent(mBinding.zinc.text.toString()),//锌
                getContent(mBinding.copper.text.toString()),//铜
                getContent(mBinding.potassium.text.toString()),//钾
                getContent(mBinding.phosphorus.text.toString()),//磷
                getContent(mBinding.sodium.text.toString()),//钠
                getContent(mBinding.calcium.text.toString()),//钙
                getContent(mBinding.selenium.text.toString()),//硒
                getContent(mBinding.magnesium.text.toString()),//镁
            )
        )

    }

    fun getContent(inputStr: String): String =
        if (NotNullHelper.notEmpty(inputStr)) {
            inputStr
        } else {
            ""
        }
}